﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebAsp.DAL;
using WebAsp.DTO;

namespace WebAsp.Admin.News
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Button Back after sign out.
            Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();
            //---------------------------------------------------------
            ListNews.DataSource = NewsDAL.GetList();
            ListNews.DataBind();
        }

        protected void btnCreat_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Admin/News/Create.aspx");
        }

        protected void ListNews_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditRow")
                Response.Redirect("/Admin/News/Edit.aspx?ID=" + e.CommandArgument);
            if (e.CommandName == "DeleteRow")
            {
                NewsDAL.Delete(int.Parse(e.CommandArgument.ToString()));
                Response.Redirect("/Admin/News");
            }
        }
    }
}